#ifndef __ICE_AGENT_H
#define __ICE_AGENT_H
#include <string>
#include <vector>
#include <rtc_base/third_party/sigslot/sigslot.h>
#include "ice/ice_transport_channel.h"
#include "base/event_loop.h"
#include "ice/port_allocator.h"
namespace xrtc
{

    class IceAgent : public sigslot::has_slots<>
    {

    public:
        IceAgent(EventLoop *el, PortAllocator *allocator);
        ~IceAgent();
        IceTransportState IceState() { return ice_state_; }
        bool CreateChannel(EventLoop *el, const std::string &tranpport_name, IceCandidateComponent component);
        IceTransportChannel *GetChannel(const std::string &transport_name, IceCandidateComponent component);
        void GatheringCandidate(); // 收集candidate
        void SetIceParams(const std::string &transport_name, IceCandidateComponent component, const IceParameters &ice_params);
        void SetRemoteIceParams(const std::string &transport_name, IceCandidateComponent component, const IceParameters &ice_params);
        sigslot::signal4<IceAgent *, const std::string &, IceCandidateComponent, const std::vector<Candidate> &> SignalCandidateAllocateDone; // signal4 需要四个参数
        sigslot::signal2<IceAgent *, IceTransportState> SignalIceState;

    private:
        std::vector<IceTransportChannel *>::iterator GetChannel_(const std::string &transport_name, IceCandidateComponent component);
        void OnCandidateAllocateDone(IceTransportChannel *channel, const std::vector<Candidate> &);
        void OnIceRecevingState(IceTransportChannel *);
        void OnIceWritableState(IceTransportChannel *);
        void OnIceStateChanged(IceTransportChannel *);
        void UpdateState();

    private:
        EventLoop *el_;
        std::vector<IceTransportChannel *> channels_;
        PortAllocator *allocator_;
        IceTransportState ice_state_ = IceTransportState::kNew;
    };

} // namespace xrtc

#endif